Skip to content

避免 menuCommand 更新在 Tab 移除后触发#828

Merged
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:避免-menuCommand-更新在-Tab-移除后触发-1
Oct 10, 2025

Hidden character warning

The head ref may contain hidden characters: "\u907f\u514d-menuCommand-\u66f4\u65b0\u5728-Tab-\u79fb\u9664\u540e\u89e6\u53d1-1"
Merged

避免 menuCommand 更新在 Tab 移除后触发#828
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:避免-menuCommand-更新在-Tab-移除后触发-1

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

之前原案有這個,改動後消失了。補回去

// 避免 menuCommand 更新在 Tab 移除后触发
list.length = 0;
this.updateMenuCommands.delete(tabId);
}
Copy link
Copy Markdown
Member

@CodFrm CodFrm Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解 this.updateMenuCommand 在 updateMenuCommand 最后面肯定会删除的,且updateMenuCommand是一个同步函数,这实际是一个无效操作

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

呀。原来现在是 ScriptMenu 没删 (${CACHE_KEY_TAB_SCRIPT}${tabId}
对。会跑。所以如果推了10个registerMenu, onRemoved 后才执行,那么就会变成在 script.menus 里残留

@CodFrm CodFrm requested a review from Copilot October 10, 2025 15:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

这个PR修复了一个竞态条件问题,防止在标签页(Tab)移除后仍然触发菜单命令更新。主要是在标签页关闭时清理相关的菜单更新队列,避免内存泄漏和潜在的错误。

  • 移除了未使用的 isUpdateMenuDirty 变量
  • 优化了 updateMenuCommand 方法中的变量声明位置和使用
  • 在标签页关闭时添加了菜单更新队列的清理逻辑

Comment thread src/app/service/service_worker/popup.ts
@CodFrm CodFrm merged commit c64f6d9 into scriptscat:main Oct 10, 2025
2 of 3 checks passed
@cyfung1031 cyfung1031 deleted the 避免-menuCommand-更新在-Tab-移除后触发-1 branch October 17, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants